import { Component, OnInit } from '@angular/core';
import { HttpService } from '@core/services/http.service';
import { ActivatedRoute, Router } from '@angular/router';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import swal from "sweetalert2";


@Component({
  selector: 'app-cloudpart',
  templateUrl: './cloudpart.component.html',
  styleUrls: ['./cloudpart.component.less']
})
export class CloudpartComponent implements OnInit {

    loading = false;
    list: any = [];
    pageSize: number;
    pageIndex = 1;
    ident: string;
    IP_PORT = this.Http.IP_PORT;
    total: number;
    token: string;
    style: any = {
        width: '70%'
    };
    constructor(private Http: HttpService,
        private msg: NzMessageService,
        private confirmServ: NzModalService,
        public router: Router,
        private ActiveRoute: ActivatedRoute) { }

    ngOnInit() {
        this.getData();
    }
    getData() {
        this.pageSize = 7;
        this.Http.getProject('cloud', { pi: this.pageIndex, ps: this.pageSize }).then(data => {
            this.list = [];
            this.list.push({
                'p_name': '',
                'p_image': ''
            });
            this.list = this.list.concat(data.list);
            this.total = data.total;
        });
    }
    deleteProjectById(id) {
        this.confirmServ.confirm({
            title: '是否要删除该项目?',
            okText: '确定',
            cancelText: '取消',
            onOk: () => {
                this.Http.deleteProjectById({ p_id: id, isCloud: 'true' }).subscribe(res => {
                    swal(`${res['msg']}`, '', 'info');
                    this.getData();
                });

            },
            onCancel() {

            }
        });

    }

    preview(p_id, isCloud, isUse) {
        this.router.navigate(['/xiangmu/full/advance'], { relativeTo: this.ActiveRoute, queryParams: { p_id: p_id, isCloud: isCloud, isUse: isUse } });
    }

}
